/**
 * Copyright &copy; 2015-2020 XiHe Digital All rights reserved.
 */
package com.ruoyi.ctcx.config;



import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;


import javax.annotation.PostConstruct;

/**
 * 全局配置类
 *
 * @author 郭翔铭
 * @version 2014-06-25
 */
@Component
public class Global {



    /**
     * 上传文件基础虚拟路径
     */
    public static final String USERFILES_BASE_URL = "/bfiles/";


    @Value("${uploadfiles.basedir}")
    public String baseDir;
    @Value("${uploadfiles.tmpdir}")
    private String tmp;
    public static String staticBaseDir;
    public static String staticTmpDir;

    @PostConstruct
    public void init() {
        staticBaseDir = baseDir;
        staticTmpDir = tmp;
    }

    @Autowired
    public static WebApplicationContext webApplicationConnect;



    /**
     * 获取上传文件的根目录
     *
     * @return
     */
    public static String getUserfilesBaseDir() {
        if (StringUtils.isBlank(staticBaseDir)) {
            try {
                staticBaseDir = webApplicationConnect.getServletContext().getRealPath("/");
            } catch (Exception e) {
                return "";
            }
        }
        if (!staticBaseDir.endsWith(StringUtils.URL_SEP)) {
            staticBaseDir += StringUtils.URL_SEP;
        }
        return staticBaseDir;
    }





}
